package com.gopay.common.user.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.cust.CustCorpInfoConstants;
import com.gopay.common.domain.cust.CustInfoExtendItem;
import com.gopay.common.user.dao.CustInfoExtendItemDAO;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * @CustInfoExtendItemDAOImpl.java
 * @author wanggang
 * @2013-11-25 下午3:05:13 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("custInfoExtendItemDAO")
public class CustInfoExtendItemDAOImpl extends BaseDAOImpl<CustInfoExtendItem, Serializable> implements
        CustInfoExtendItemDAO {

    /*
     * (non-Javadoc)
     * 
     * @see com.gopay.common.user.dao.CustInfoExtendItemDAO#
     * findCustInfoExtendItemByCustIdItemkey(java.lang.String, java.lang.String)
     */
    @Override
    public CustInfoExtendItem findCustInfoExtendItemByCustIdItemkey(String custId, String itemKey) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustInfoExtendItem.class);
        criteria.add(Restrictions.eq("custId",custId));
        criteria.add(Restrictions.eq("itemKey",itemKey));
        List<CustInfoExtendItem> list = this.findByCriteria(criteria);
        return list.size()>0 ? list.get(0): null;
    }
    
    @Override
    public boolean findByCustId(String custId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustInfoExtendItem.class);
        criteria.add(Restrictions.eq("custId",custId));
        return this.findCountByCriteria(criteria) > 0;
    }

    @Override
    public CustInfoExtendItem findCustInfoExtendItemByCustId(String custId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustInfoExtendItem.class);
        criteria.add(Restrictions.eq("custId",custId));
        criteria.add(Restrictions.eq("itemKey", CustCorpInfoConstants.ITEM_KEY_FUNDORGNO));
        List<CustInfoExtendItem> list = this.findByCriteria(criteria);
        return ( list!=null && list.size()>0 ) ? list.get(0): null;
    }

    @Override
    public CustInfoExtendItem findCustInfoExtendItemByItemKey(String itemKey,String itemValue) {

        DetachedCriteria criteria = DetachedCriteria.forClass(CustInfoExtendItem.class);
        criteria.add(Restrictions.eq("itemKey",itemKey));
        criteria.add(Restrictions.eq("itemValue",itemValue));
        List<CustInfoExtendItem> list = this.findByCriteria(criteria);


        return list.size()>0 ? list.get(0): null;
    }
}
